package {{.pkg}}

import (
	"encoding/json"
	"fmt"
	"strings"
	"time"

	"github.com/osamingo/jsonrpc/v2"
)


type TxID struct {
    TxID  int
}

type Time time.Time

func (t Time) MarshalJSON() ([]byte, error) {
	timestamp := time.Time(t).Format("2006-01-02 15:04:05")
	return json.Marshal(timestamp)
}

func (t *Time) UnmarshalJSON(b []byte) error {
	var v string
	if err := json.Unmarshal(b, &v); err != nil {
		return err
	}
	parse, err := time.Parse("2006-01-02 15:04:05", v)
	if err != nil {
		return err
	}
	*t = Time(parse)
	return nil
}

type FlexError jsonrpc.Error

var ErrNotFound = &FlexError{
	Code:    -32003,
	Message: "not found",
}

func (e *FlexError) Error() string {
	return (*jsonrpc.Error)(e).Error()
}

func (e *FlexError) Is(err error) bool {
	return strings.Contains(err.Error(), fmt.Sprintf("jsonrpc: code: %d", e.Code))
}
